package main

import (
	"errors"
	"fmt"
)

func fn1() {
	fmt.Println("fn1")
}

func fn2() {
	defer func() {
		err := recover()
		if err != nil {
			fmt.Println(err)
		}
	}()
	fmt.Println("fn2")
	// 抛出异常
	panic("我是panic")
}

func fn3(a, b int) int {
	defer func() {
		err := recover()
		if err != nil {
			fmt.Println(err)
		}
	}()
	return a / b
}

func fn4(a, b int) (int, error) {
	if b == 0 {
		return 0, errors.New("除数不能为0")
	}
	return a / b, nil
}

func main() {
	fn1()
	fn2()
	fmt.Println(fn3(10, 0))
	fmt.Println("-----------------------------------------------")
	fmt.Println(fn4(10, 2))
	fmt.Println("-----------------------------------------------")
}
